package com.youku.plugins.feedback
{
   import flash.display.MovieClip;
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.events.PlayerControlEvent;
   import com.youku.events.PluginEvent;
   import com.youku.utils.BaseUtil;
   import com.youku.plugins.PluginEventDispather;
   
   public class FeedbackMediator extends Object
   {
      
      public function FeedbackMediator(param1:MovieClip, param2:IPlayerProxy, param3:PluginEventDispather) {
         super();
         this._mainMC = param1;
         this._playerProxy = param2;
         this._feedback = new Feedback();
         this.addEvents();
      }
      
      private var _mainMC:MovieClip;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _feedback:Feedback;
      
      private var _text:String = "";
      
      private function addEvents() : void {
         this._playerProxy.addEventListener(PlayerControlEvent.FULLSCREEN_CHANGED,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.PLAYER_SIZE_CHANGED,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_TOGGLE_PAUSEPLAY,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_PAUSE,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_RESUME,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PluginEvent.CONTROL_BAR_DRAG_DRAGGING,this.onPluginEvent);
         this._playerProxy.addEventListener(PluginEvent.CONTROL_BAR_DRAG_FINISH,this.onPluginEvent);
         this._playerProxy.addEventListener(PluginEvent.CONTROL_BAR_SEEK,this.onPluginEvent);
         this._playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CHANGE_VOLUME,this.onPluginEvent);
         this._playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CLICK_LOOP,this.onPluginEvent);
         this._playerProxy.addEventListener(PluginEvent.TOOLBOX_DATA_CHANGED,this.onPluginEvent);
         this._playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CLICK_ROTATE,this.onPluginEvent);
      }
      
      private function onPlayerControlEvent(param1:PlayerControlEvent) : void {
         var _loc4_:* = NaN;
         var _loc5_:* = NaN;
         var _loc6_:* = false;
         var _loc2_:* = "";
         var _loc3_:* = true;
         switch(param1.type)
         {
            case PlayerControlEvent.PLAYER_SIZE_CHANGED:
            case PlayerControlEvent.FULLSCREEN_CHANGED:
               _loc4_ = param1.data.width;
               _loc5_ = param1.data.height;
               _loc6_ = param1.data.fullscreen;
               this._feedback.layout(_loc4_,_loc5_,_loc6_);
               _loc3_ = false;
               break;
            case PlayerControlEvent.CORE_TOGGLE_PAUSEPLAY:
               if(this._playerProxy.playerData.videoIsPause)
               {
                  _loc2_ = "播放";
               }
               else
               {
                  _loc2_ = "暂停";
               }
               _loc3_ = param1.data.useraction;
               break;
            case PlayerControlEvent.CORE_PAUSE:
               _loc3_ = false;
               if((param1.data) && (param1.data.hasOwnProperty("useraction")))
               {
                  if(param1.data.useraction == true)
                  {
                     _loc2_ = "暂停";
                     _loc3_ = true;
                  }
               }
               break;
            case PlayerControlEvent.CORE_RESUME:
               _loc2_ = "播放";
               break;
         }
         if(_loc3_)
         {
            this._mainMC.addChild(this._feedback);
            this._feedback.show(_loc2_);
         }
      }
      
      private function onPluginEvent(param1:PluginEvent) : void {
         var _loc3_:* = false;
         var _loc2_:* = true;
         switch(param1.type)
         {
            case PluginEvent.CONTROL_BAR_DRAG_DRAGGING:
            case PluginEvent.CONTROL_BAR_DRAG_FINISH:
            case PluginEvent.CONTROL_BAR_SEEK:
               this._text = BaseUtil.formatTime(param1.data.time);
               break;
            case PluginEvent.CONTROL_BAR_CHANGE_VOLUME:
               this._text = "音量: " + String(int(param1.data.volume * 100)) + "%";
               if(param1.data.volume == 0)
               {
                  this._text = "静音";
               }
               if(param1.data.userAction == false)
               {
                  _loc2_ = false;
               }
               break;
            case PluginEvent.CONTROL_BAR_CLICK_LOOP:
               _loc3_ = param1.data.loop;
               this._text = "单曲循环: " + (_loc3_?"开":"关");
               break;
            case PluginEvent.TOOLBOX_DATA_CHANGED:
               this._text = "设置成功";
               break;
            case PluginEvent.CONTROL_BAR_CLICK_ROTATE:
               this._text = "画面旋转";
               break;
         }
         if(_loc2_)
         {
            this._mainMC.addChild(this._feedback);
            this._feedback.show(this._text);
         }
      }
      
      private function hide() : void {
      }
   }
}
